<template>
  <div id="app">
    <router-view v-if="isRouterAlive"/>
  </div>
</template>

<script>
export default {
  provide :function() { 
    return { 
      reload: this.reload
    } 
  },
  data () {
    return {
      isRouterAlive: true
    }
  },
  methods: {
    reload() { 
      this.isRouterAlive=false; 
      this.$nextTick(function(){ 
        this.isRouterAlive=true 
      }) 
    }
  },
  created() {
	console.log(this.isRouterAlive)
    if(sessionStorage.getItem("store")) {
      this.$store.replaceState(
        Object.assign(
          {},
          this.$store.state,
          JSON.parse(sessionStorage.getItem("store"))
        )
      )
      sessionStorage.removeItem("store");
    }
    window.addEventListener('beforeunload', ()=>{
      sessionStorage.setItem("store", JSON.stringify(this.$store.state));
    })
  },
  beforeDestroy() {
    this.$store.commit('index', true);
  },
}
</script>

<style lang="less" type="text/css">
body,html{margin: 0px;padding: 0px;}
// #app {
//   font-family: Avenir, Helvetica, Arial, sans-serif;
//   -webkit-font-smoothing: antialiased;
//   -moz-osx-font-smoothing: grayscale;
//   text-align: center;
//   color: #2c3e50;
// }

// #nav {
//   a {
//     font-weight: bold;
//     color: #2c3e50;

//     &.router-link-exact-active {
//       color: #42b983;
//     }
//   }
// }
</style>
